package com.hina.rec.endpoint;

import com.hina.rec.application.service.SystemProductService;
import com.hina.rec.common.model.Result;
import com.hina.rec.endpoint.req.FileUploadReq;
import com.hina.rec.endpoint.req.SysProductCompareReq;
import com.hina.rec.endpoint.req.SysProductSearchReq;
import com.hina.rec.endpoint.res.SysProductCompareRes;
import com.hina.rec.endpoint.res.SysProductRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统产品数据接口
 *
 * @author liaosp
 * @since 2025-05-23
 */
@Tag(name = "系统产品数据接口", description = "系统产品数据接口")
@RestController
@RequestMapping("/sys_product")
@RequiredArgsConstructor
public class SystemProductEndpoint {

    private final SystemProductService systemProductService;

    /**
     * 搜索产品数据接口
     *
     * @param req 搜索请求
     * @return 产品数据列表
     */
    @PostMapping("/search")
    @Operation(summary = "搜索产品数据接口", description = "搜索产品数据接口(不分页,参数必须包含月份)")
    public Result<List<SysProductRes>> search(@RequestBody SysProductSearchReq req) {
        List<SysProductRes> list = systemProductService.search(req);
        return Result.success(list);
    }

    /**
     * 导入产品数据接口
     *
     * @param req 文件上传请求
     * @return 导入结果
     */
    @PostMapping("/import")
    @Operation(summary = "导入产品数据接口", description = "导入产品数据接口(使用fastexcel)")
    public Result<String> importExcel(@RequestBody FileUploadReq req) {
        String result = systemProductService.importExcel(req);
        return Result.success(result);
    }

    /**
     * 对比产品数据接口
     *
     * @param req 对比请求
     * @return 对比结果
     */
    @PostMapping("/compare")
    @Operation(summary = "对比产品数据接口", description = "对比产品数据接口")
    public Result<List<SysProductCompareRes>> compare(@RequestBody SysProductCompareReq req) {
        List<SysProductCompareRes> list = systemProductService.compare(req);
        return Result.success(list);
    }
}